<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:p="http://primefaces.org/ui"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

	<ui:composition template="/meringerTemplate.xhtml">

		<ui:define name="content">
		   <h:form id="form">  
  				<p:messages id="msg" autoUpdate="true" />
			    <p:dataTable var="car" value="#{carModelBean.cars}" rowKey="#{car.name}" paginator="true" rows="2"  
			               filteredValue="#{carModelBean.filteredCars}" id="carsTable">  
			  
			  
			        <p:column headerText="Model" sortBy="#{car.name}" filterBy="#{car.name}" id="model">  
			        <img src="#{car.imgPath}" />
			            #{car.name}  
			        </p:column>  
			  
			        <p:column headerText="Price" sortBy="#{car.price}" filterBy="#{car.price}" id="price">  
			            #{car.price}  
			        </p:column>  
			  
			        <p:column headerText="Handling" sortBy="#{car.initHandling}" filterBy="#{car.initHandling}" id="initHandling">  
			            #{car.initHandling}  
			        </p:column>  
			        <p:column headerText="Top Speed" sortBy="#{car.maxTopSpeed}" filterBy="#{car.maxTopSpeed}" id="maxTopSpeed">  
			            #{car.maxTopSpeed}  
			        </p:column> 
			        <p:column headerText="Acceleration" sortBy="#{car.maxAcceleration}" filterBy="#{car.maxAcceleration}" id="maxAcceleration">  
			            #{car.maxAcceleration}  
			        </p:column> 
			         <p:column id="save">  
			         
			         
			         <ui:fragment rendered="#{userBean.currentUser.budget >= car.price}">
			             <p:commandButton id = "btn" value="Buy" action="#{carModelBean.saveBoughtCar(car.modelID)}">
    					</p:commandButton>
    				 </ui:fragment>
    				 <ui:fragment rendered="#{!(userBean.currentUser.budget >= car.price)}">
    				 	Not enough money
    				 </ui:fragment>
			        </p:column> 
			  
			    </p:dataTable>  
			  
			 
			    
				
			</h:form>  
			
		</ui:define>
	</ui:composition>

</html>
